// pages/my/pj.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    no_pic:('/static/defalut_face.png'),
    tip:'好评',
    tipArr:['','差评','一般','一般','不错','很好'],
    sub:{id:0,star:5,con:'',nm:0,imgs:[]},
    serverUrl:'',
    serverHeader:{},
    info:{}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(e) {
    this.setData({
      serverUrl:wx.util.interfaceUrl()+"upload",
      serverHeader:{
        'Deer-Device-Type':'wxapp',
        'Deer-Api-Version':wx.util.ver,
        'Deer-Api-Token': wx.util.getToken()
      }
    })
    if(e.id){
      this.setData({
        'sub.id':e.id
      })
    }
    this.load();
  },
  async load(){
    let res=await wx.util.post("order/evaluate_info",this.data.sub);
    this.setData({
      info:res.data
    })
  },
  async subData(){
    if(this.data.sub.con==""){
      wx.util.toast('请输入评价内容');
      return;
    }
    await wx.util.post("order/evaluate_add",this.data.sub,false);
    wx.setStorageSync("order_tab",-1);
    wx.util.toast('提交成功');
    wx.navigateBack();
  },
  result: function(s) {
    let e=s.detail;
    this.setData({
      'sub.imgs':e.imgArr
    })
  },
  remove: function(e) {
    this.data.sub.imgs.splice(e.detail.index,1);
    this.setData({
      'sub.imgs':this.data.sub.imgs
    })
  },
  setNm(e){
    this.setData({
      'sub.nm':e.detail.value.length==0?0:1
    })
  },
  setInput(e) {
    let key=e.currentTarget.dataset.key;
    this.setData({
      [key]: e.detail.value
    })
  },
  change(e) {
    this.setData({
      'sub.star': e.detail.index,
      tip:this.data.tipArr[e.detail.index]
    })
  }
})